const data = [
  {
    id: 1,
    name: "张三",
    children: [
      {
        id: 12,
        name: "张三丰",
        children: [
          {
            id: 121,
            name: "王二",
            children: [
              { id: 1212, name: "赵冬青" },
              { id: 1213, name: "赵青" },
            ],
          },
        ],
      },
    ],
  },
  {
    id: 2,
    name: "李四",
    children: [
      {
        id: 12,
        name: "李丰收",
        children: [
          {
            id: 121,
            name: "王二",
            children: [
              { id: 1212, name: "赵冬青" },
              { id: 1213, name: "赵青" },
            ],
          },
        ],
      },
    ],
  },
];
const result = data.reduce(function (prev, curr) {
  prev.push({ id: curr.id, name: curr.name, parentId: curr.parentId });
  curr.children &&
    curr.children.forEach((v) => {
      v.parentId = curr.id;
      arguments.callee(prev, v);
    });
  return prev;
}, []);
console.log(result);
